<?php
class installModel extends baseModel{

    public function create_db($data){
        $model=new cpModel($data);
        $sql="CREATE DATABASE IF NOT EXISTS `".$data['DB_NAME']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;";
        return @$model->query($sql);
    }

    public function run_sql($data,$sql_array=array()){
        $model=new cpModel($data);
        foreach($sql_array as $sql)
        {
            if(!@$model->db->query($sql)){
                return false;
            }
        }
        return true;
    }

    public function conreplace($value){
        if($value=='true') return true;
            if($value=='false') return false;
            if(preg_match("/^\d*$/",$value) && strlen($value)<10) return intval($value);
            return $value; 
    }

    public function form_config($data){
        unserialize($data['create']);
        unserialize($data['test']);
        foreach ($data as $key => $value) {
            if(is_array($value)){
                foreach ($value as $k=> $v) {
                    $config[$key][$k]=$this->conreplace($v);
                }
            }else $config[$key] = $this->conreplace($value);
        }
        return $config;
    }


}

?>